package com.qjz.diancan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qjz.diancan.mapper.CartMapper;
import com.qjz.diancan.model.entity.Cart;
import com.qjz.diancan.model.entity.Dish;
import com.qjz.diancan.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    @Transactional
    public void addShopCar(Integer id, Dish dish)
    {
        cartMapper.addShopCar(id, dish);
    }

    @Override
    public PageInfo<Cart> findByPage(Integer pageNum, Integer pageSize, Integer id)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<Cart> list = cartMapper.findByPage(id);
        return new PageInfo<>(list);
    }

    @Override
    @Transactional
    public void deleteShopCarData(Integer id)
    {
        cartMapper.deleteShopCarData(id);
    }

    @Override
    @Transactional
    public void updateShopCarData(Cart cart)
    {
        cartMapper.updateShopCarData(cart);

    }
}
